import requests
import json
from dataclasses import dataclass, asdict
from datetime import datetime

@dataclass
class Gin:
    ID: int
    CreatedAt: datetime
    UpdatedAt: datetime
    DeletedAt: str

@dataclass
class Want(Gin):
    Title: str
    Answers: list

resp = requests.get('http://localhost:3000/wants')
objs = json.loads(resp.content)

for obj in objs:
    print(Want(**obj).Title)


want = Want(ID=0, CreatedAt=None, UpdatedAt=None, DeletedAt=None, 
            Title='新的', Answers=[])
resp = requests.post('http://localhost:3000/want', json=want.__dict__)
if resp.status_code == 200:
    want = Want(**json.loads(resp.content))
    print("want created. id:", want.ID)
    want.Title = "修改，被删除"
    want = Want(**want.__dict__)
    resp = requests.put('http://localhost:3000/want/'+str(want.ID), json=want.__dict__)
    if resp.status_code == 200:
        print("want updated.")
        resp = requests.delete('http://localhost:3000/want/'+str(want.ID))
        if resp.status_code == 200:
            want = Want(**json.loads())
            print("want deleted. id:", want.ID, ", deletedAt:", want.DeletedAt)
        else:
            print(resp.content)
    else:
        print(resp.content)
else:
    print(resp.content)
